package l1j.server.server.datatables.lock;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

import l1j.server.server.datatables.sql.GameConfigTable;
import l1j.server.server.datatables.storage.GameConfigStorage;
import l1j.server.server.templates.GameConfig;


public class GameConfigReading {

	private final Lock _lock;

	private final GameConfigStorage _storage;
	private static GameConfigReading _instance;

	private GameConfigReading(){
		_lock = new ReentrantLock(true);
		_storage = new GameConfigTable();
	}
	
	public static GameConfigReading get(){
		if(_instance == null){
			_instance = new GameConfigReading();
		}
		return _instance;
	}
	
	/**
	 * 資料預先載入
	 */
	public void load() {
		_lock.lock();
		try {
			_storage.load();
			
		} finally {
			_lock.unlock();
		}
	}
	
	
	public GameConfig getConfig(final int id){
		_lock.lock();
		try {
			return _storage.getConfig(id);
		} finally {
			_lock.unlock();
		}
	}
	
	public void updateB1(final int id , final int type){
		_lock.lock();
		try {
			_storage.updateB1(id, type);
		} finally {
			_lock.unlock();
		}
	}
	
	public void updateB2(final int id , final int type){
		_lock.lock();
		try {
			_storage.updateB2(id, type);
		} finally {
			_lock.unlock();
		}
	}
	
	public void updateB3(final int id , final int type){
		_lock.lock();
		try {
			_storage.updateB3(id, type);
		} finally {
			_lock.unlock();
		}
	}
	
	public void updateB4(final int id , final int type){
		_lock.lock();
		try {
			_storage.updateB4(id, type);
		} finally {
			_lock.unlock();
		}
	}
	
	public void updateB5(final int id , final int type){
		_lock.lock();
		try {
			_storage.updateB5(id, type);
		} finally {
			_lock.unlock();
		}
	}
	
	public void updateB6(final int id , final int type){
		_lock.lock();
		try {
			_storage.updateB6(id, type);
		} finally {
			_lock.unlock();
		}
	}

	
	public void deleteConfig(final int id){
		_lock.lock();
		try {
			_storage.deleteConfig(id);
		} finally {
			_lock.unlock();
		}
	}
}
